package com.yuebook.smartrpc.framework.cluster.impl;

import com.yuebook.smartrpc.framework.cluster.ClusterStrategy;
import com.yuebook.smartrpc.framework.helper.IPHelper;
import com.yuebook.smartrpc.framework.model.ProviderService;
import java.util.List;

/**
 * 原地址hash算法
 * @author honglei
 * @date 2018/11/20 上午10:40
 */
public class HashClusterStrategyImpl implements ClusterStrategy {

    @Override
    public ProviderService select(List<ProviderService> providerServices) {
        int size = providerServices.size();
        String localIp = IPHelper.localIp();
        int hashCode = localIp.hashCode();
        return providerServices.get(hashCode % size);
    }
}
